class FeatureRequestsController < ApplicationController

  before_filter :login_required

  in_place_edit_for :feature_request, :summary
  in_place_edit_for :feature_request, :body

  def index
    @feature_requests = User.feature_requests(params[:user_id],
                                              params[:page])
    @listing_all_frs = params[:user_id] ? false : true
  end

  def new
    @feature_request = FeatureRequest.new(:user_id => @current_user.id)
  end

  def create
    @feature_request = FeatureRequest.new(params[:feature_request])

    if @feature_request.user_id == @current_user.id && @feature_request.save
      flash[:notice] = 'Your feature request has been received, thanks for your interest in the site!'
      redirect_to user_feature_requests_path(@current_user)
    else
      render :action => 'new'
    end
  end

  def destroy
    feature_request = FeatureRequest.find_by_id(params[:id])
    if feature_request && feature_request.user_id == @current_user.id
      feature_request.delete
      flash.now[:notice] = 'Feature request successfully deleted'
    else
      flash.now[:error] = 'Your feature request could not be deleted!'
    end

    render :partial => 'shared/flash_messages'
  end

end
